import { RuleObject } from 'ant-design-vue/lib/form/interface';

const validators = {
    phone(rule: RuleObject, value: string) {
        const regExp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
        if (!regExp.test(value)) {
            return Promise.reject(rule.message);
        }
        return Promise.resolve();
    },
    password(rule: RuleObject, value: string) {
        const regExp = /^(\S){6,20}$/;
        if (!regExp.test(value)) {
            return Promise.reject(rule.message);
        }
        return Promise.resolve();
    },
    email(rule: RuleObject, value: string) {
        const regExp = new RegExp(
            '^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$',
            ''
        );
        if (!regExp.test(value)) {
            return Promise.reject(rule.message);
        }
        return Promise.resolve();
    },
};

export default validators;
